<template>
	
	<view class="cart-empty" v-if="cartArr.length === 0">购物车为空</view>
	
	
	<view class="cart-container" v-else>
		
		<my-address></my-address>
		
		<view class="cart-title">
			<uni-icons type="shop" size="20" color="gray"></uni-icons>
			<text>购物车</text>
		</view>
		
		<uni-swipe-action>
			<block v-for="(goods, i) in cartArr" :key="i">
				<uni-swipe-action-item :right-options="options" @click="swipeItemClickHandler(goods)">
					<my-goods :goods = "goods" :showRadio = "true" @radio-change="radioChange" :showNumbox = "true" @num-change="numberChange"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		
		<my-settle></my-settle>
		
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	
	import badgeMix from '@/mixins/tabbar-badge.js'
	
	export default {
		
		mixins: [badgeMix],
		
		computed: {
			...mapState('m_cart', ['cartArr']),
		},
		
		data() {
			return {
				options: [{
				  text: '删除',
				  style: {
				    backgroundColor: '#C00000'
				  }
				}]
			};
		},
		onLoad() {
			
		},
		
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'deleteGoods']),
			
			radioChange(goods) {
				this.updateGoodsState(goods)
			},
			numberChange(goods) {
				this.updateGoodsCount(goods)
			},
			
			swipeItemClickHandler(goods) {
				this.deleteGoods(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.cart-title {
		height: 50px;
		display: flex;
		align-items: center;
		padding: 0 5px;
		border-bottom: 1px solid #C0C0C0;
		text {
			font-size: 15px;
			margin-left: 10px;
			
		}
	}
</style>
